<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientAction_file extends KBClientAction_common
{

	function &execute($controller, $manager) {
		
		require_once APP_MODULE_DIR . 'file/entry/inc/FileEntryModel.php';
		require_once APP_MODULE_DIR . 'file/entry/inc/FileEntryModel_dir.php';
		
		
		$entry_id = (int) $controller->getRequestVar('category_id'); // here it is entry to what file attached
		$file_id = (int) $controller->getRequestVar('entry_id');
		$view_id = $controller->getRequestVar('view_id');
		
		// deny to upload not attached file
		//if($view_id == 'file') {
			if(!$manager->isAttachment($entry_id, $file_id)) {
				$controller->go();
			}
		//}
		
		$manager =& new FileEntryModel_dir;
		$manager->setFileSetting( KBClientModel::getSettings(200) );		
		$data = &$manager->getById($file_id);
		
		//echo "<pre>"; print_r($data); echo "</pre>";
		//exit;
		
		if(!$data || empty($data['active'])) {
			$controller->go();
		}
		
		$manager->sendFileDownload($data);
		$manager->countDownload($file_id);
		exit;
	}
	
}
?>